#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QTcpSocket>
#include <QHostAddress>
#include <QMessageBox>
#include "pack.h"
#include "userinterface.h"
#include "schedule.h"

QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE

class Widget : public QWidget {
    Q_OBJECT
    friend class Form;
public:
    explicit Widget(QWidget *parent = nullptr);
    ~Widget();
    // 在Widget类中添加获取socket的方法
    QTcpSocket* getClientSocket() const { return client; }
    QPixmap byteArr2Pic(QByteArray &arr);


private slots:
    void on_pushButton_clicked();  // 注册
    void on_pushButton_2_clicked(); // 登录
    void on_pushButton_3_clicked(); // 连接服务器
    void onReadyRead();
    void checkInput();
    void on_pushButton_5_clicked();

    void on_pushButton_4_clicked();



    void on_checkBox_clicked();

private:
    Ui::Widget *ui;
    QTcpSocket* client;
    QHostAddress ip;
    int port;
    Userinterface* userinterface;
    schedule* userschedule;
    QString currentUsername; // 新增：存储当前登录用户名
    void handleLoginResponse(const Pack& pack);
    int num=0;
    Pack readed_pack;
    int readed_pack_size = 0;
    int unreaded_pack_size = 0;
    int readed_size = 0;
    int readed_size_size = 0;
    int unreaded_size_size = 0;
    QByteArray part_camera_pic; // 用来缓存部分摄像头图片
    bool isAgreed = false;

};

#endif // WIDGET_H
